unit ui_main;

{$IFDEF FPC}
  {$mode delphi}
{$ENDIF}

interface

uses
  zglControls;

procedure Init();
procedure Draw();
procedure Update(dt: Double);

var
  MainGUI: zglTGUI;
  mainPnl: zglTPanel;

implementation

uses
  g_vars, zglHeader;

const
  mainPnlH = 50;
var
  mouseEntred: Boolean = False;
  BtnAdd: zglTButton;
  BtnDel: zglTButton;
  BtnGrow: zglTButton;

procedure OnMouseEnter(Sender: zglTCtrl);
begin
  mouseEntred := True;
end;

procedure OnMouseLeave(Sender: zglTCtrl);
begin
  mouseEntred := False;
end;

procedure OnSelectEvent(Sender: zglTCtrl; MouseButton: Cardinal);
var
  btn: zglTButton;
  i: Integer;
  p: Pointer;
begin
  BtnDel.Down := False;
  BtnAdd.Down := False;
  BtnGrow.Down := False;
  btn := zglTButton(Sender);
  btn.Down := True;
  if btn = BtnGrow then
    RightState := rtBlow;
  if btn = BtnAdd then
    RightState := rtAdd;
  if btn = BtnDel then
    RightState := rtDel;
end;

procedure Init();
var
  Btn: zglTButton;
  Tex: zglPTexture;
begin
  MainGUI := zglTGUI.Create(SCREEN_WIDTH, SCREEN_HEIGHT, nil);
  mainPnl := zglTPanel.Create(MainGUI, $88FFFFFF);
  mainPnl.BBDraw := True;
  mainPnl.BBColor := $FFFFFFFF;
  mainPnl.Width := 200;
  mainPnl.Height := mainPnlH;
  mainPnl.Left := -1;
  mainPnl.Top := -mainPnlH + 1;
  mainPnl.OnMouseEnter := OnMouseEnter;
  mainPnl.OnMouseLeave := OnMouseLeave;

  Tex := resMan.LoadTex('btn_plus.png');
  tex_SetFrameSize(Tex, 30, 30);
  BtnAdd := zglTButton.Create(mainPnl, Tex);
  BtnAdd.Left := 10;
  BtnAdd.Top := 10;
  BtnAdd.Width := 30;
  BtnAdd.Height := 30;
  BtnAdd.CanDown := True;
  BtnAdd.OnMouseUp := OnSelectEvent;
  BtnAdd.Down := True;

  Tex := resMan.LoadTex('btn_minus.png');
  tex_SetFrameSize(Tex, 30, 30);
  BtnDel := zglTButton.Create(mainPnl, Tex);
  BtnDel.Left := 50;
  BtnDel.Top := 10;
  BtnDel.Width := 30;
  BtnDel.Height := 30;
  BtnDel.CanDown := True;
  BtnDel.OnMouseUp := OnSelectEvent;


  Tex := resMan.LoadTex('btn_blow.png');
  tex_SetFrameSize(Tex, 30, 30);
  BtnGrow := zglTButton.Create(mainPnl, Tex);
  BtnGrow.Left := 90;
  BtnGrow.Top := 10;
  BtnGrow.Width := 30;
  BtnGrow.Height := 30;
  BtnGrow.CanDown := True;
  BtnGrow.OnMouseUp := OnSelectEvent;
end;

procedure Draw();
begin
  MainGUI.Draw();
end;

procedure Update(dt: Double);
begin
  MainGUI.Update(dt);
  //Выдвигание меню
  if (mouseEntred) and (mainPnl.Top < -1) then
  begin
    mainPnl.Top := mainPnl.Top + 0.2 * dt;
    if mainPnl.Top > -1 then
      mainPnl.Top := -1;
  end;
  if (not mouseEntred) and (mainPnl.Top > (-mainPnlH + 1)) then
  begin
    mainPnl.Top := mainPnl.Top - 0.2 * dt;
    if mainPnl.Top < (-mainPnlH + 1) then
      mainPnl.Top := (-mainPnlH + 1);
  end;
end;

finalization
  MainGUI.Free;

end.

